﻿namespace Lilium.Web.Mvc

open System.Web.Mvc

// Extended controller interface for the lilium MVC library.
type IController =
    abstract member CreateView :
        string          // masterName
        -> string       // viewName
        -> obj          // model
        -> ViewResult

    abstract member Context : System.Web.HttpContextBase
        
// Base class for custom controllers.
type Controller() = 
    inherit System.Web.Mvc.Controller()

    interface IController with
        member self.CreateView masterName viewName model = self.View(viewName, masterName, model)
        member self.Context = self.HttpContext

(*  -- не работает в C#!
// Controller adapter for backward compatibility.
module ControllerAdapter =
    // Creates IController adapter for CSharp-style controller
    // Requires public method ViewResult CreateView(viewName, masterName, model)
    // Note that viewName and masterName swapped in the F# version. This is done to ease
    // closure creation (master page likely will not change for controller actions)
    let inline wrapSCharpController controller =

        let createView masterName viewName model = (^controller: (member CreateView: (string * string * obj) -> ViewResult) controller, (viewName, masterName, model))
        let context = (^controller: (member HttpContext: System.Web.HttpContextBase) controller)

        let adapter = { 
            new IController with
                member self.CreateView masterName viewName model = createView masterName viewName model 
                member self.Context = context }

        adapter
*)